﻿@page "/Admin/SettingsManager"
@using JxAudio.Web.Vo
@using JxAudio.Web.Enums
@using Microsoft.Extensions.Localization
@using JxAudio.Core.Service
@using System.Diagnostics.CodeAnalysis

@inject IStringLocalizer<SettingsVo> SettingsVoLocalizer
@inject IStringLocalizer<SettingsManager> SettingsLocalizer
@inject SettingsService SettingsService
@inject ToastService ToastService

<ValidateForm Model="SettingsVo" OnValidSubmit="Save">
    <div class="row g-3">
        <div class="col-6">
            <h3>@SettingsLocalizer["Title"]</h3>
        </div>
        <div class="col-auto ms-auto">
            <Button Text="@SettingsLocalizer["Save"]" ButtonType="ButtonType.Submit"></Button>
        </div>
    </div>
    <Settings SettingsVo="SettingsVo"></Settings>
</ValidateForm>

@code {
    [NotNull]
    private SettingsVo? SettingsVo { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();
        SettingsVo = SettingsVo.GetSettings(SettingsService);
    }

    private Task Save(EditContext arg)
    {
        SettingsVo.SetSettings(SettingsService);
        ToastService.Success(SettingsLocalizer["ToastTitle"], SettingsLocalizer["SuccessContent"]);
        return Task.CompletedTask;
    }

}